#include "UIManager.h"
#include "Controls/Window.h"
#include "Test/TestWindow1.h"
namespace cxgui
{
using namespace test;
void UIManager::Update()
{
	for(auto window : _windows)
	{
		window->Update();		
	}
}

void UIManager::Draw()
{
	for(auto window : _windows)
	{
		window->Draw();
	}
}

void UIManager::KeyDown(const KeyEvent& e)
{
	switch (e.getCode())
	{
	case e.KEY_q:
		_activeWindow->SetHorizontalContentAlignment(HorizontalAlignment::Left);
		break;
	case e.KEY_w:
		_activeWindow->SetHorizontalContentAlignment(HorizontalAlignment::Center);
		break;
	case e.KEY_e:
		_activeWindow->SetHorizontalContentAlignment(HorizontalAlignment::Right);
		break;
	case e.KEY_r:
		_activeWindow->SetHorizontalContentAlignment(HorizontalAlignment::Stretch);
		break;
	case e.KEY_a:
		_activeWindow->SetVerticalContentAlignment(VerticalAlignment::Bottom);
		break;
	case e.KEY_s:
		_activeWindow->SetVerticalContentAlignment(VerticalAlignment::Center);
		break;
	case e.KEY_d:
		_activeWindow->SetVerticalContentAlignment(VerticalAlignment::Top);
		break;
	case e.KEY_f:
		_activeWindow->SetVerticalContentAlignment(VerticalAlignment::Stretch);
		break;
	case e.KEY_z:
		{
			auto& testWindow = dynamic_cast<TestWindow1&>(*_activeWindow);
			testWindow.AddButton();			
		}
		break;
	case e.KEY_x:
		{
			auto& testWindow = dynamic_cast<TestWindow1&>(*_activeWindow);
			testWindow.RemoveButton();
		}
		break;
	default:
		break;
	}
}

void UIManager::MouseClick(const MouseEvent& e)
{
}

void UIManager::AddWindow(shared_ptr<Window> window, bool active)
{
	_windows.push_back(window);
	if(active)
	{
		_activeWindow = window;
	}
}

UIManager::~UIManager()
{
}
}